Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jack-midi support #19246

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open

jack-midi support #19246

wants to merge 60 commits into from

Conversation

lyrra
Copy link
Contributor

@lyrra lyrra commented Sep 1, 2023

  • I signed the CLA

Purpose

For linux users, the ability to at runtime switch between alsa and jack audio+midi driver.

Changes

  • Make both jack and alsa(linuxdriver) more similar to osx-driver
  • Make jack and alsa drivers "subdrivers" of linuxdriver (AudioDriverState).

class design changes

Before:

AudioModule
│
├── LinuxAudioDriver
│   │
│   Alsa
│   └──> device: "default"
│
├── OSXAudioDriver
│   ...
│
└── WasapiAudioDriver
    ...

MidiModule
│
├── LinuxAudioDriver
│   │
│   ├────> AlsaMidiOutPort
│   └────> AlsaMidiInPort
│   
:

After:


AudioModule
│
|         MidiModule
│             |
├── AudioMidiManager (was LinuxAudioDriver)
│        |      │
│        |      ├─── JackDriverState
│        |      │    │
│        |      │    (jack-code)
│        |      │    └──> jack client open
│        |      └──> AlsaDriverState
│        |                      │
│        |              (alsa-code)
│        |                      └──> device: "default"
│        │
│        + LinuxMidiOutPort
│        │
│        ├────> JackMidiOutPort
│        ├────> AlsaMidiOutPort
│        + LinuxMidiInPort
|          :
│
├── OSXAudioDriver
│   ...
│
└── WasapiAudioDriver
    ...

MidiModule
│
├── AudioMidiManager (was LinuxAudioDriver)
│   │
│   + LinuxMidiOutPort
│   │
│   ├────> JackMidiOutPort
│   ├────> AlsaMidiOutPort
│   + LinuxMidiInPort
:

Audio Tests

  • start with jack, play and hear audio OK
  • start with alsa, play and hear audio OK
  • start with jack, switch to alsa, then play OK
  • start with alsa, switch to jack, then play OK
  • switch from jack to alsa during play OK
  • switch from alsa to jack during play OK

Midi tests

  • start fluidsynth in verbose mode, musescore and qjackctl (to midi-connect them), verify midi-events are logged by fluidsynth.

Optional cleanups / redesign

Remove LinuxAudioDriver and keep only AlsaAudioDriver and JackAudioDriver as two independent implementations. To switch between them, you need to add another class, something like IAudioDriverProvider. This is what you need to add to IoC (and remove the drivers from IoC). Access the driver through this class, like:

class IAudioDriverProvider ...
{
...

        std::shared_ptr<IAudioDriver> driver() const;
  
        void swithDriver(const std::string& name); 
        async::Chanel<std::string /*name*/> dirverChanged() const;
}


class SomeClass
    Inject<IAudioDriverProvider > audioDriverProvider;


...

     audioDriverProvider()->driver();

This greatly simplifies everything, each class becomes simple and does one thing.
Moreover, such a system is easily scalable; we can easily add other drivers, cross-platform or platform-specific.

Not in scope for this PR

  • MIDI-channel-per-instrument

Known cleanups & fixes before merge

  • send foreign commits upstream:
    Misc. needed for jack #22373
  • cleanup: avoid global in app
  • If possible do mutual dependency Injection between module Audio and Midi.
    Testing confirmed, can't inject modules.
    Injection is used, but not at modul level.
  • de-pollute any interfaces that got sprinkled with data members
  • ensure no public data members begins with m_ (those should be private)
  • remove sample-rate dropdown OR make it work,
    No 'requires restart' added
  • automatic connection to audio ports upon start
    Not in scope, brings in too much arbitrary heuristics code from Mu3.
  • Possible to switch between jack/alsa driver (currently it crashes)
  • Possible to switch bufferSize in jack without crash (possible in alsa)
  • Possible to disable jack-transport via configuration checkbox

@lyrra lyrra force-pushed the jack branch 3 times, most recently from ce43ca7 to b218652 Compare September 1, 2023 09:42
@lyrra lyrra changed the title jack: cleanup, remove usage of static variables jack/alsa: cleanup, remove usage of static variables Sep 1, 2023
@lyrra lyrra force-pushed the jack branch 6 times, most recently from 7638762 to 22128db Compare September 2, 2023 11:18
@lyrra lyrra changed the title jack/alsa: cleanup, remove usage of static variables jack/alsa: switch runtime support Sep 2, 2023
@lyrra lyrra force-pushed the jack branch 2 times, most recently from 999e2a8 to 7a2a941 Compare September 2, 2023 12:29
@lyrra lyrra marked this pull request as ready for review September 2, 2023 13:20
@lyrra lyrra force-pushed the jack branch 7 times, most recently from 3e582e1 to 24705bc Compare September 8, 2023 04:57
@cbjeukendrup cbjeukendrup linked an issue Sep 8, 2023 that may be closed by this pull request
@lyrra lyrra force-pushed the jack branch 2 times, most recently from f56bf85 to 01f03a1 Compare September 10, 2023 22:15
@lyrra lyrra mentioned this pull request Sep 11, 2023
@lyrra lyrra force-pushed the jack branch 4 times, most recently from 932c742 to 77c9dbe Compare September 15, 2023 05:50
@lyrra lyrra force-pushed the jack branch 2 times, most recently from 3e3dc9e to c03609b Compare February 21, 2025 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MuseScore not supporting JACK audio anymore (Linux)